package buaa.com.adapter;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

import buaa.com.crazzyguess.R;
import buaa.com.util.Globals;
import buaa.com.util.ImageUtil;

/**
 * Created by Administrator on 2016/4/25.
 */
public class GameAdapter extends BaseAdapter{
    private List<Map<String ,Object>> values;
    private Context cxt;

    public GameAdapter(List<Map<String, Object>> values, Context cxt) {
        this.values = values;
        this.cxt = cxt;
    }

    @Override
    public int getCount() {
        return values.size();
    }

    @Override
    public Object getItem(int position) {
        return values.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(cxt).inflate(R.layout.grid_list,null);
            convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Globals.SCREEN_HEIGHT/9));

        }
        Map<String,Object> map = values.get(position);
        TextView stage = (TextView)convertView.findViewById(R.id.stage);
        stage.setText(map.get("stage").toString());
        Log.d("map.get(overFlag)","............."+map.get("overFlag"));
        if((boolean)map.get("overFlag")){
            stage.setBackgroundDrawable(new BitmapDrawable(cxt.getResources(), ImageUtil.getCanSelect()));
        }else {
            stage.setBackgroundDrawable(new BitmapDrawable(cxt.getResources(),ImageUtil.getNoSelect()));
        }

        return convertView;
    }
}
